<?
include_once("./qpass_config.php");
include_once("$gnuPath/common.php");

include_once("./lib_qpass_inc.php");
admin_check();

${"g".$gnuVersion}['title'] = "Qpass 대분류 관리";  
include_once("./head_qpass.php");
 


if($mode == 'add') {

	$sql = "select count(*) from qpass_catBig where big_code = '$big_code' ";
	/*echo $sql;*/

	
	$result_count = mysql_query($sql);
	$cat_count = mysql_result($result_count, 0,0);
	

	if($cat_count > 0) {

		  echo "<script>alert('코드 $big_code 은(는) 이미 생성된 코드이니, 목록에서 처리하세요.');</script>";
	}
	else {

		  $sql = "insert into qpass_catBig (big_code, big_name) values ('$big_code', '$big_name')";
		  /*echo $sql;*/

		  mysql_query($sql);

		  if( mysql_errno() > 0 ) echo "error: ".mysql_error();
	}
}

else if($mode == 'modify' && $big_code) {

	$sql = "update qpass_catBig set big_name = '$big_name' where big_code = '$big_code' ";
	/*echo $sql;*/

	mysql_query($sql);
}

else if($mode == 'delete' && $big_code) {

	$sql = "delete from qpass_catBig where big_code = '$big_code' ";
	mysql_query($sql);
}

?>


<script type='text/javascript'> 

function code_check(code, next_field) {


    if( isNaN(code.value) ) {
	
	      alert("코드는 숫자만 가능합니다. (10~99)\t");  

		  code.value = '';
		  code.focus();
          return;
    }



    if( code.value.length == 1 && code.value == 0 ) {
	
	      alert("코드는 0 으로 시작하지 않아야 합니다.\t");  

		  code.value = '';
		  code.focus();
          return;
    }



	if(code.value.length == 2) next_field.focus();

}




function add_check(f) {


    if( f.big_code.value.length < 2 ) {
	
	      alert("코드는 두자리수로 입력하세요.");  

		  f.big_code.focus();
          return;
    }


    if( f.big_name.value == '' ) {
	
	      alert("분류명을 입력하세요.");  

		  f.big_name.focus();
          return;
    }



	f.mode.value = 'add';
	f.submit();
    
}



function line_modify(code) {

	var f = document.send_form;

	f.mode.value = 'modify';

	f.big_code.value = code;
	f.big_name.value = document.getElementById('name_'+code).value;

	f.submit();
}



function line_delete(code) {

	var f = document.send_form;

	if( !confirm("삭제할까요?") ) return;

	f.mode.value = 'delete';
	f.big_code.value = code;

	f.submit();
}


</script>





<form name='send_form' method="post" style='margin:0' action='<?=$PHP_SELF?>'>

<input type='hidden' name='mode' value=''>
<input type='hidden' name='big_code' value=''>
<input type='hidden' name='big_name' value=''>

</form>




<form name='cat_form' method="post" style='margin:0' action='<?=$PHP_SELF?>'>
<input type='hidden' name='mode' value=''>


<p align='center' style='margin:20px 0 0 0; font-weight:bold;'>대분류 목록</p>


<table width='400' cellspacing='1' cellpadding='5' align='center' style='margin-top:10px; background-color:#ccc' border='0'>
<tr style="background-color:white"> 
	  
<td align='center' width='50'>코드</td> 
<td align='center'>분류명</td>
<td align='center' width='90'>처리</td> 
    
</tr>  
    
<?
  $sql = "select * from qpass_catBig order by big_code";

  $result_cat = mysql_query($sql);
  $row_cat = mysql_fetch_array($result_cat);

  if(!$row_cat) {

	    echo "<tr height='50'><td colspan='3' align='center'>대분류 자료가 없습니다.</td></tr>";

		$next_code = 10;
  }
  else {


	    do {
			  $code = $row_cat[big_code];

			  echo "<tr style='background-color:white'>  <td align='center' width='50'>$code</td>";

			  echo "<td align='center'><input type='text' id='name_{$code}' value='$row_cat[big_name]' class='ed' onclick=\"this.style.color='blue';\" style=''></td>";
			  
			  echo "<td align='center' width='90'><input type='button' value='수정' onclick='line_modify($code)' onfocus='this.blur()' class='btn02_qpass'> <input type='button' value='삭제' onclick='line_delete($code)' onfocus='this.blur()' class='btn02_qpass'> </td>  </tr>";

			  if($code != 99) $next_code = $code + 1;


		} while( $row_cat = mysql_fetch_array($result_cat) );
  

  }



?>




</table>





<p align='center' style='margin:30px 0 0 0; font-weight:bold;'>대분류 추가</p>

<p align='center'>
<table align='center' width='400' cellspacing='1' cellpadding='5' style='margin: 10px 0 50px 0; background-color:#ccc' border='0'>

<tr style='background-color:white'> 
	  
<td align='center' width='50'>코드</td> 
<td align='center'>분류명</td>
<td align='center' width='90'>처리</td> 
    
</tr>  


<tr style='background-color:white'> 
	  
<td align='center' width='50'><input type='text' name='big_code' size='2' maxlength='2' class='ed' style='text-align:center;' onkeyup='code_check(this, this.form.big_name)' value='<?=$next_code?>'></td> 

<td align='center'><input type='text' name='big_name' maxlength='30' class='ed' style='width:150px; ime-mode:active;'></td>

<td align='center' width='90'>
<input type='button' value="추가하기" onclick="add_check(this.form)" class='btn02_qpass'>
</td> 
    
</tr>  

<tr style='background-color:white'><td colspan='3' align='center' style='color:green;'>코드는 10 ~ 99 사이 숫자로 입력하세요.</td></tr>
    
</table>
</p>


</form>


<? include_once("./tail_qpass.php"); ?>

